package cn.jjzd.info.listener;

import cn.jjzd.info.service.InfoHtmlService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class InfoListener {

    @Autowired
    private InfoHtmlService infoHtmlService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "JJZD.INFO.SAVE.QUEUE",durable = "true"),
            exchange = @Exchange(value = "JJZD.INFO.EXCHANGE",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key = {"info.insert","info.update"}
    ))
    public void save(Long id){
        if(id == null){
            return ;
        }
        this.infoHtmlService.createHtml(id,1);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "JJZD.INFO.DELETE.QUEUE",durable = "true"),
            exchange = @Exchange(value = "JJZD.INFO.EXCHANGE",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key = {"info.delete"}
    ))
    public void delete(Long id){
        if(id == null){
            return ;
        }
        this.infoHtmlService.deleteHtml(id,1);
    }
}
